/**
 * Created by ACER on 2017/4/10.
 */
app.controller('personal-profile',function($scope,$http){
    var token = localStorage.getItem("token");
    if(!token){
        $.alert('请先登录',function(){
            location.href='#login';
        });
        return;
    }
    $scope.userInfo = {};

    $scope.getPersonalInfo=function(){
        if(token){
            $http(
                {   method:'get',
                    url:app.netPath+'/users/details/show',
                    headers: {Authorization:token}
                }
            ).then(function(res){


                if(!res.data.error){

                    $scope.userInfo=res.data.data;
                    //年龄
                    if($scope.userInfo.userBirthday){
                        $scope.userInfo.age= parseInt((new Date().getTime() - new Date($scope.userInfo.userBirthday).valueOf())/31536000000);

                    }


                    $scope.userInfo.userSexWord = $scope.userInfo.userSex == 0? '男':'女';
                    var avatarImg = {};

                    if(res.data.data.userAvatarAddress){
                        avatarImg.imgAddress = app.netPath+'/resources/img/'+res.data.data.userAvatarAddress;
                        $scope.userInfo.avatarImg = avatarImg;
                    }
                }
                else {
                    $.alert('出错了，刷新试试！')
                }

            },function(){
                $.alert('网络或设置错误');
            })
        }
    }
});